<template>
    <div>
        <!-- 单据详情的弹出层开始 -->
        <el-dialog
                :title="title"
                :visible.sync="open"
                width="1000px"
                center
                append-to-body
        >
            <el-table  border :data="purchaseItemTableList">
                <el-table-column label="详情ID" width="180" align="center" prop="itemId" />
                <el-table-column label="单据ID" width="200" align="center" prop="purchaseId" />
                <el-table-column label="采购数量" align="center" prop="purchaseNumber" />
                <el-table-column label="批发价" prop="tradePrice" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.tradePrice|rounding }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="批发额" align="center" prop="tradeTotalAmount">
                    <template slot-scope="scope">
                        <span>{{ scope.row.tradeTotalAmount|rounding }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="批次号" align="center" prop="batchNumber" />
                <el-table-column label="药品名称" align="center" prop="medicinesName" />
                <el-table-column label="单位" align="center" prop="conversion" />
                <el-table-column label="创建时间" align="center" prop="unit" />
            </el-table>
            <span slot="footer" class="dialog-footer">
    <el-button @click="cancel">取 消</el-button>
  </span>
        </el-dialog>
        <!-- 单据详情的弹出层结束 -->

        <div>
            供应商名称<el-select v-model="searchForm.providerId" placeholder="请输入供应商名称">
            <el-option
                    v-for="item in deptData"
                    :key="item.providerId"
                    :label="item.providerName"
                    :value="item.providerId">
            </el-option>
        </el-select>
            申请人<el-input v-model="searchForm.applyUserName" placeholder="请输入申请人" style="width: 100px;"></el-input>
            <el-button type="primary" @click="queryAll()">搜索</el-button>
            <el-button type="primary" @click="resetFormFiled()">重置</el-button>
        </div>
        <div>
            <el-button type="primary" style="float: left;" @click="handleToNewPurchase()">审核通过</el-button>
            <el-button type="primary" style="float: left;" @click="NohandleToNewPurchase()">审核不通过</el-button>
            <el-button type="primary" style="float: left;" @click="handleViewItem()">查看详情</el-button>
        </div>
        <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column label="单据ID" align="center" width="200" prop="purchaseId">
            </el-table-column>
            <el-table-column prop="provider.providerName" label="供应商" width="200">
            </el-table-column>
            <el-table-column prop="purchaseTradeTotalAmount" label="采购批发总额" width="120">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="120" :formatter="statusformat">
            </el-table-column>
            <el-table-column prop="applyUserName" label="申请人" width="120">
            </el-table-column>
            <el-table-column prop="storageOptUser" label="入库操作人" width="120">
            </el-table-column>
            <el-table-column prop="storageOptTime" label="入库时间" width="200">
            </el-table-column>
            <el-table-column prop="auditMsg" label="审核信息" width="120">
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" width="200">
            </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.current"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="page.size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.total">
        </el-pagination>
    </div>
</template>

<script>
    import qs from "qs";

    export default {
        name: "Examine",
        methods:{
            resetFormFiled(){
                this.searchForm={};
                this.initTable();
            },
            cancel(){
                this.open=false;
            },
            // 查看详情//------------------------------未实现
            handleViewItem() {
                this.open = true;
                const purchaseId = this.multipleSelection[0].purchaseId
                this.title = '单据编号为【' + purchaseId + '】的采购详情数据'
                this.$axios.post("medicine/Examine/examine",this.multipleSelection[0]).then(r => {
                    this.purchaseItemTableList = r.data.t;
                })
            },
            //供应商下拉框
            queryDept(){
                this.$axios.get('medicine/provider/getAll1').then(r=>{
                    this.deptData=r.data.t;
                })
            },
            //审核不通过
            NohandleToNewPurchase() {
                this.$axios.post('medicine/Examine/Nomodification',this.multipleSelection[0]).then(r=>{
                    this.initTable();
                })
            },
            //审核通过
            handleToNewPurchase() {
               this.$axios.post('medicine/Examine/modification',this.multipleSelection[0]).then(r=>{
                   this.initTable();
               })
            },
            //状态字典解析
            statusformat(row){
                let val=row.status ;
                return this.formatDict(this.statusOptions,val)
            },
            //状态
            initStatus(){
                this.$axios.get("system/api/dict/data/findByType/his_order_status").then(r=>{
                    this.statusOptions = r.data.t;
                })
            },
            //批量
            handleSelectionChange(val) {
                this.multipleSelection = val;

            },
            //搜索
            queryAll(){
                this.page.current=1;
                this.initTable();

            },
            //分页
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.page.size=val;
                this.initTable();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.page.current=val;
                this.initTable();
            },
            //刷新表格  //模糊查询
            initTable() {
                let search={...this.page,...this.searchForm};
                this.$axios.get('medicine/Examine/getAll/',{params:search}).then(r => {
                    this.tableData = r.data.t.records;
                    //刷新总条数
                    this.page.total=r.data.t.total;
                })
            }
        },
        data() {
            return {
                tableData: [],
                page:{
                    total:10,
                    current:1,
                    size:10
                },
                searchForm: {},
                deptData:[],
                multipleSelection:[],
                statusOptions:[],
                open:false,
                title:'',
                purchaseItemTableList:{},
            }
        },
        created() {
            this.initTable();
            this.initStatus();
            //供应商
            this.queryDept();
        }
    }
</script>

<style scoped>

</style>



